finding the nth term of a sequence